import React from 'react'
  import PropTypes from 'prop-types'
  import { connect } from 'dva'
import UserList from './List'

function User({location, dispatch, user, loading}) {

  function onDeleteItem(id) {
    dispatch({type: 'user/delete', payload: {id}})
  }

  function onEditItem(item) {
    dispatch({
      type: 'user/showModal',
      payload: {
        type: 'update',
        curItem: item
      }
    })
  }

  function onStatusItem(item) {
    dispatch({
      type: 'user/updateStatus',
      payload: {
        curItem: item
      }
    })
  }

  function onDeleteBatch(ids) {
    dispatch({
      type: 'user/deleteBatch',
      payload: { ids }
    })
  }

  function onSearch(values){
    dispatch({
      type: 'user/search',
      payload: values
    })
  }

  const listProps = {
    user,
    loading,
    location,
    onDeleteItem,
    onEditItem,
    onStatusItem,
    onDeleteBatch,
    onSearch,
  }

  return (
    <div className='content-inner'>

      <UserList {...listProps}/>

    </div>
  );
}

User.propTypes = {
  user: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func
};

function mapStateToProps({ user }){
  return { user }
}

export default connect(mapStateToProps)(User);
